package experiment4;

public class Bank {
    private Account[] bank;

    public Bank() {
    }

    public Bank(Account[] bank) {
        this.bank = bank;
    }

    public Account[] getBank() {
        return bank;
    }

    public void setBank(Account[] bank) {
        this.bank = bank;
    }

    public void chargeAToB(Account p1, Account p2,int money) {
        //查找顾客
        boolean flag1 = false;
        boolean flag2 = false;


        int Index1=0;
        int Index2=0;
        for (int i = 0; i < getBank().length; i++) {
            //找到两个就转
            if (getBank()[i] == p1) {
                flag1 = true;
                Index1 = i;
            }
            if (getBank()[i] == p2) {
                flag2 = true;
                Index2 = i;
            }
        }

        if (flag1 && flag2) {
            //都存在
            p2.addMoney(money);
            p1.getMoney(money);
            System.out.println("转账成功");

        } else {
            //某一个不存在或都不存在
            if(flag1==false){
                System.out.println(p1.getUserName()+"不存在");
            }
            if(flag2==false){
                System.out.println(p2.getUserName()+"不存在");
            }
        }

    }

}
